<?php
/**
 * Ajax总控制器
 * 仲伟涛 2011-3
 */
error_reporting(0);

class Resume_Page_Ajax extends Resume_Page_Abstract {
	private $resumeDb;
	public function validate(ME_Request $input, ME_Response $output) {
		return true;
	}
	public function loadDb() {
		$this->resumeDb = Db_Resume::instance();
	}
	
	//验证用户名的可用性
	public function doCheckUserName(ME_Request $input, ME_Response $output) {
		$userName = trim($input->get('userName'));
		$retnArr = Libs_UcUser::checkUserName($userName);
		$returnStr = "{flag:";
		$returnStr .= (int)$retnArr['flag'] > 0 ? 1 : 0;
		$returnStr .= ",msg:'" . $retnArr['msg'] . "'}";
		echo $returnStr;
		exit();
	}
	
	//验证MAILL的可用性
	public function doCheckMail(ME_Request $input, ME_Response $output) {
		$mail = trim($input->get('mail'));
		$retnArr = Libs_UcUser::checkMail($mail);
		$returnStr = "{flag:";
		$returnStr .= (int)$retnArr['flag'] > 0 ? 1 : 0;
		$returnStr .= ",msg:'" . $retnArr['msg'] . "'}";
		echo $returnStr;
		exit();
	}
	//后台选项级联
	public function doSelectRel(ME_Request $input, ME_Response $output) {
		$this->loadDb();
		$modId = (int)$input->get("modId");
		$classId = $input->get("val");
		
		$subWhere = " and classid = {$classId} and module_type = {$modId} ";
		$sql = "select subclassid ,name from category_list where isdel = 0 and subclassid <> 0 {$subWhere} order by orderby desc ";
		
		$dataArr = $this->resumeDb->getAll($sql);
		
		$json_arr = array();
		$json = array();
		$json['When'] = $val;
		$json['Value'] = "";
		$json['Text'] = '请选择'; //iconv('gbk','utf-8','请选择');
		$json_arr[] = $json;
		
		if( $dataArr ){
			foreach( $dataArr as $re ){
				$json = array();
				$json['When'] = $val;
				$json['Value'] = $re['subclassid'];
				$json['Text'] = $re['name'];
				$json_arr[] = $json;
			}
		}
		//print_r($json_arr);exit;
		print_r(json_encode($json_arr));
		exit();
	}
	
	//获取证书
	public function doGetCertGroupDetail(ME_Request $input, ME_Response $output) {
		$this->loadDb();
		$groupId = (int)$input->get("groupId");
		if( $groupId == 0 ){
			return false;
		}
		
		$config = ME_Config::get("MyResume");
		$groupmember = $config['groupmember'];
		
		$result = $groupmember[$groupId];
		
		print_r(json_encode($result));
		exit();
	}
	
	// 学校名字的suggest服务  added by hongzx 2011.5.29
	public function doGetSchoolList(ME_Request $input, ME_Response $output) {
		$prefix = $input->get("q");
		$this->loadDb();
		$sql = "select Name from resume_school where Name like '" . $prefix . "%' LIMIT 0,6";
		$dataArr = $this->resumeDb->getAll($sql);
		
		$schools = array();
		if( $dataArr ){
			foreach( $dataArr as $item ){
				array_push($schools, $item["Name"]);
			}
		}
		if( count($schools) ){
			$school_strs = implode("|", $schools);
		}else{
			$school_strs = "";
		}
		
		print_r($school_strs);
		exit();
	}

}
